/*
 * @Author: szx
 * @Date: 2022-06-30 13:40:49
 * @LastEditTime: 2022-06-30 13:47:37
 * @Description:
 * @FilePath: \leetcode\500-599\535\535.js
 */
/**
 * Encodes a URL to a shortened URL.
 *
 * @param {string} longUrl
 * @return {string}
 */
var encode = function (longUrl) {
    this.dataBase = new Map();
    let key;
    while (true) {
        key = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
        if (!dataBase.has(key)) {
            break;
        }
    }
    this.dataBase.set(key, longUrl);
    return 'http://tinyurl.com/' + key;
};

var decode = function (shortUrl) {
    const p = shortUrl.lastIndexOf('/') + 1;
    const key = parseInt(shortUrl.substring(p));
    return this.dataBase.get(key);
};
